package online.foxnull2.foxmall.order.vo.orderConfirm;

import lombok.Data;
import lombok.experimental.Accessors;
import org.springframework.util.ObjectUtils;

import java.math.BigDecimal;
import java.util.List;

@Data
@Accessors(chain = true)
public class OrderConfirmVo {

    private List<MemberReceiveAddress> memberReceiveAddresses;
    private List<CartItem> cartItems;
    /**
     * 积分
     */
    private Integer integration;
    private String orderToken;

    /**
     * private BigDecimal totalAmount;
     * private BigDecimal payPrice;
     */

    public BigDecimal getTotalAmount() {
        if (!ObjectUtils.isEmpty(getCartItems())) {
            BigDecimal totalAmount = new BigDecimal("0.00");
            for (CartItem item : getCartItems()) {
                totalAmount = totalAmount.add(item.getTotalPrice());
            }
            return totalAmount;
        }
        return null;
    }

    public BigDecimal getPayPrice() {
        return getTotalAmount();
    }

    public Integer getCartItemCount() {
        List<CartItem> cartItems = getCartItems();
        if (!ObjectUtils.isEmpty(cartItems)) {
            Integer count = 0;
            for (CartItem item : cartItems) {
                count += item.getCount();
            }
            return count;
        }
        return null;
    }
}
